package com.nineclock.system.controller;


import com.nineclock.common.entity.Result;
import com.nineclock.message.dto.SysAllowedJoinCompanyUserDTO;
import com.nineclock.system.SysCompanyContactConfigController.SysCompanyControllerApi;
import com.nineclock.system.dto.SysApplyJoinCompanyUserDTO;
import com.nineclock.system.dto.SysChangeMainManagerDTO;
import com.nineclock.system.dto.SysCompanyDTO;
import com.nineclock.system.dto.SysCompanyUserDTO;
import com.nineclock.system.service.SysCompanyService;
import com.nineclock.system.service.SysCompanyUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/company")
public class SysCompanyControllerControllrt implements SysCompanyControllerApi {

    @Autowired
    private SysCompanyService sysCompanyService;
    @Autowired
    private SysCompanyUserService sysCompanyUserService;
    /*
     * 查看企业数据基本信息
     *
     * */
    @Override
    @GetMapping
    public Result<SysCompanyDTO> querySysCompanyInfo() {
        SysCompanyDTO sysCompanyDTO = sysCompanyService.querySysCompanyInfo();
        return Result.success(sysCompanyDTO);
    }

    /*
     * 上传企业Logo
     * */
    @Override
    @PostMapping("/uploadOSS")
    public Result<String> uploadCompanyLogo(MultipartFile file) throws IOException {
        String logoUrl = sysCompanyService. uploadCompanyLogo(file);

        return Result.success(logoUrl);
    }

    /*
     *更新企业的基本信息
     * */
    @Override
    @PutMapping
    public Result updateCompanyInfo(@RequestBody SysCompanyDTO sysCompanyDTO) {

        sysCompanyService.updateCompanyInfo(sysCompanyDTO);
        return Result.success();
    }

    /*
     * 获取当前企业信息
     * */
    @Override
    @GetMapping("/getCurrentAdmin")
    public Result<SysCompanyUserDTO> getCurrentAdmin() {

        SysCompanyUserDTO companyAdmin=sysCompanyUserService.getCurrentAdmin();
        return Result.success(companyAdmin);
    }

    @Override
    @PostMapping("/config/admin")
    public Result updateChangeMainManagerAdmin(@RequestBody SysChangeMainManagerDTO sysChangeMainManagerDTO) {

        sysCompanyService.updateChangeMainManagerAdmin(sysChangeMainManagerDTO);

        return Result.success();
    }

    @Override
    @GetMapping("/list")
    public Result<List<SysCompanyDTO>> queryCompanyByName(String keyword) {
        List<SysCompanyDTO> companyDTOList =sysCompanyService.queryCompanyByName(keyword);
        return Result.success(companyDTOList);
    }

    /*加入企业*/
    @Override
    @PostMapping("/applyJoinCompany")
    public Result applyJoinCompany(@RequestBody SysApplyJoinCompanyUserDTO sysApplyJoinCompanyUserDTO) {

        sysCompanyService.applyJoinCompany(sysApplyJoinCompanyUserDTO);
        return Result.success();
    }

    //加入企业审核
    @Override
    @PostMapping("/allowedJoinCompany")
    public Result allowedJoinCompany(SysAllowedJoinCompanyUserDTO allowedJoinCompanyUserDTO) {

        sysCompanyService.allowedJoinCompany(allowedJoinCompanyUserDTO);
        return Result.success();
    }


}
